package csu.common.test.escape;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import rescuecore2.worldmodel.EntityID;

import csu.model.object.CSUBlockade;
import csu.model.object.CSUEdge;
import csu.model.object.CSURoad;

public class EscapeData_1 implements EscapeData {
	private int[] blockade_2078976033 = { 125000, 92148, 125000, 94000, 126840,
			94000, 126840, 92509, 125951, 92242, 125888, 93137 };
	private int[] blockade_2078976032 = { 126499, 76000, 125814, 76937, 125319,
			78000, 126840, 78000, 126840, 76000, 126283, 77195 };
	private int[] blockade_2078976035 = { 125000, 88000, 125000, 90000, 126840,
			90000, 126840, 88000, 125920, 89000 };
	private int[] blockade_2078976034 = { 125319, 92000, 125814, 93062, 126499,
			94000, 126840, 94000, 126840, 92000, 126283, 92804 };
	private int[] blockade_2078976063 = { 126840, 27175, 126840, 29000, 126840,
			34000, 126840, 36000, 126840, 37000, 126840, 39000, 126840, 39824,
			127815, 39174, 128574, 38286, 129067, 37211, 129243, 36000, 129243,
			34000, 129243, 31000, 129067, 29788, 128574, 28713, 127815, 27825,
			127925, 33499 };
	private int[] blockade_2078976007 = { 125000, 34000, 125000, 36000, 126840,
			36000, 126840, 34000, 125920, 35000 };
	private int[] blockade_2078976006 = { 125000, 27000, 125000, 29000, 126414,
			29000, 126414, 27000, 125707, 28000 };
	private int[] blockade_2078976005 = { 125000, 27000, 125000, 29000, 126840,
			29000, 126840, 27175, 126419, 27000, 125912, 28009 };
	private int[] blockade_2078976022 = { 125000, 49000, 125000, 51000, 126840,
			51000, 126840, 49000, 125920, 50000 };
	private int[] blockade_2078976020 = { 125000, 37000, 125000, 39000, 126840,
			39000, 126840, 37000, 125920, 38000 };
	private int[] blockade_2078976021 = { 125000, 58000, 125000, 60000, 126840,
			60000, 126840, 58000, 125920, 59000 };
	private int[] blockade_2078976019 = { 125000, 46000, 125000, 48000, 126840,
			48000, 126840, 46205, 126481, 46000, 125911, 47009 };
	private int[] blockade_2078976030 = { 125000, 76000, 125000, 78000, 126840,
			78000, 126840, 76000, 125920, 77000 };
	private int[] blockade_2078976028 = { 125000, 79000, 125000, 81000, 126840,
			81000, 126840, 79000, 125920, 80000 };
	private int[] blockade_2078976029 = { 125061, 79000, 124999, 79493, 125000,
			79493, 125000, 81000, 126840, 81000, 126840, 79000, 125923, 80003 };
	private int[] blockade_2078976026 = { 125000, 64000, 125000, 66000, 126840,
			66000, 126840, 64000, 125920, 65000 };
	private int[] blockade_2078976027 = { 125000, 64000, 125000, 66000, 126840,
			66000, 126840, 64000, 125920, 65000 };
	private int[] blockade_2078976024 = { 125000, 67000, 125000, 69000, 126840,
			69000, 126840, 67000, 125920, 68000 };
	private int[] blockade_2078976025 = { 125000, 67000, 125000, 69000, 126840,
			69000, 126840, 67000, 125920, 68000 };
	private int[] blockade_2078976067 = { 126840, 56617, 126840, 58000, 126840,
			60000, 126840, 64000, 126840, 66000, 126840, 67000, 126840, 69000,
			126840, 70382, 128016, 69671, 128937, 68661, 129537, 67415, 129752,
			66000, 129646, 65000, 129752, 64000, 129510, 62500, 129752, 61000,
			129537, 59584, 128937, 58338, 128016, 57328, 128124, 63505 };
	private int[] blockade_2078976066 = { 126840, 63239, 126840, 64000, 126840,
			66000, 126840, 67000, 126840, 69000, 126840, 75760, 127792, 75118,
			128533, 74244, 129014, 73188, 129185, 72000, 129185, 69000, 129185,
			67000, 129014, 65811, 128533, 64755, 127792, 63881, 127900, 69499 };
	private int[] blockade_2078976065 = { 126840, 69420, 126840, 76000, 126840,
			78000, 126840, 79000, 128750, 79459, 129023, 78000, 129023, 76000,
			129023, 73000, 128864, 71876, 128418, 70876, 127728, 70042, 127872,
			74792 };
	private int[] blockade_2078976064 = { 126840, 46205, 126840, 48000, 126840,
			49000, 126840, 51000, 126840, 56794, 127457, 56269, 127932, 55610,
			128237, 54845, 128345, 54000, 128253, 53216, 127990, 52500, 128253,
			51783, 128345, 51000, 128193, 50000, 128345, 49000, 128237, 48154,
			127932, 47389, 127457, 46730, 127498, 51486 };
	private int[] blockade_2078976069 = { 131212, 19336, 129139, 21149, 130868,
			23726, 130907, 23786, 132703, 26479, 133159, 27018, 133160, 27018,
			133160, 22240, 131605, 22657 };
	private int[] blockade_2078976068 = { 131000, 73979, 129821, 74094, 128720,
			74425, 127719, 74950, 126839, 75647, 126840, 75647, 126840, 76000,
			126840, 78000, 126840, 79000, 131000, 80000, 133160, 80000, 133160,
			73979, 130250, 76992 };
	private int[] blockade_2078976075 = { 126840, 79000, 126840, 81000, 126840,
			81579, 127987, 80695, 128750, 79459, 127526, 80086 };
	private int[] blockade_2078976078 = { 126840, 90000, 126840, 92000, 126840,
			94000, 126840, 94352, 127719, 95049, 128720, 95574, 129821, 95905,
			131000, 96020, 133160, 96020, 133160, 90000, 130132, 92851 };
	private int[] blockade_2078976077 = { 126840, 92509, 126840, 94000, 126840,
			98690, 129767, 99903, 129851, 99000, 129851, 97000, 129629, 95544,
			129008, 94266, 128055, 93232, 128238, 96467 };
	private int[] blockade_2078976076 = { 126840, 79000, 126840, 81000, 126840,
			88000, 126840, 90000, 131000, 90000, 131000, 80000, 128886, 84746 };
	private int[] blockade_2078975973 = { 126277, 16840, 127263, 18319, 127303,
			18379, 128910, 20807, 128964, 20888, 129139, 21149, 131212, 19336,
			129560, 16840, 128928, 18581 };

	// 0 -- impassable !0 -- passable
	private int[][] road_274 = { { 110000, 16840, 129560, 16840, 0 },
			{ 129560, 16840, 131212, 19336, 255 },
			{ 131212, 19336, 126840, 23160, 976 },
			{ 126840, 23160, 113160, 23160, 0 },
			{ 113160, 23160, 110000, 16840, 279 } };

	private int[][] road_929 = { { 126840, 29000, 125000, 29000, 0 },
			{ 125000, 29000, 125000, 27000, 958 },
			{ 125000, 27000, 126840, 27000, 0 },
			{ 126840, 27000, 126840, 29000, 976 } };

	private int[][] road_928 = { { 125000, 36000, 125000, 34000, 957 },
			{ 125000, 34000, 126840, 34000, 0 },
			{ 126840, 34000, 126840, 36000, 976 },
			{ 126840, 36000, 125000, 36000, 0 } };

	private int[][] road_926 = { { 126840, 48000, 125000, 48000, 0 },
			{ 125000, 48000, 125000, 46000, 955 },
			{ 125000, 46000, 126840, 46000, 0 },
			{ 126840, 46000, 126840, 48000, 976 } };

	private int[][] road_927 = { { 126840, 39000, 125000, 39000, 0 },
			{ 125000, 39000, 125000, 37000, 956 },
			{ 125000, 37000, 126840, 37000, 0 },
			{ 126840, 37000, 126840, 39000, 976 } };

	private int[][] road_924 = { { 126840, 60000, 125000, 60000, 0 },
			{ 125000, 60000, 125000, 58000, 952 },
			{ 125000, 58000, 126840, 58000, 0 },
			{ 126840, 58000, 126840, 60000, 976 } };

	private int[][] road_925 = { { 126840, 51000, 125000, 51000, 0 },
			{ 125000, 51000, 125000, 49000, 954 },
			{ 125000, 49000, 126840, 49000, 0 },
			{ 126840, 49000, 126840, 51000, 976 } };

	private int[][] road_922 = { { 126840, 69000, 125000, 69000, 0 },
			{ 125000, 69000, 125000, 67000, 950 },
			{ 125000, 67000, 126840, 67000, 0 },
			{ 126840, 67000, 126840, 69000, 976 } };

	private int[][] road_923 = { { 126840, 66000, 125000, 66000, 0 },
			{ 125000, 66000, 125000, 64000, 951 },
			{ 125000, 64000, 126840, 64000, 0 },
			{ 126840, 64000, 126840, 66000, 976 } };

	private int[][] road_920 = { { 125000, 81000, 125000, 79000, 948 },
			{ 125000, 79000, 126840, 79000, 0 },
			{ 126840, 79000, 126840, 81000, 975 },
			{ 126840, 81000, 125000, 81000, 0 } };

	private int[][] road_921 = { { 126840, 78000, 125000, 78000, 0 },
			{ 125000, 78000, 125000, 76000, 949 },
			{ 125000, 76000, 126840, 76000, 0 },
			{ 126840, 76000, 126840, 78000, 976 } };

	private int[][] road_918 = { { 126840, 94000, 125000, 94000, 0 },
			{ 125000, 94000, 125000, 92000, 946 },
			{ 125000, 92000, 126840, 92000, 0 },
			{ 126840, 92000, 126840, 94000, 974 } };

	private int[][] road_919 = { { 126840, 90000, 125000, 90000, 0 },
			{ 125000, 90000, 125000, 88000, 947 },
			{ 125000, 88000, 126840, 88000, 0 },
			{ 126840, 88000, 126840, 90000, 975 } };

	private int[][] road_976 = { { 126840, 79000, 131000, 80000, 975 },
			{ 131000, 80000, 133160, 80000, 0 },
			{ 133160, 80000, 133160, 22240, 0 },
			{ 133160, 22240, 131212, 19336, 255 },
			{ 131212, 19336, 126840, 23160, 274 },
			{ 126840, 23160, 126840, 27000, 0 },
			{ 126840, 27000, 126840, 29000, 929 },
			{ 126840, 29000, 126840, 34000, 0 },
			{ 126840, 34000, 126840, 36000, 928 },
			{ 126840, 36000, 126840, 37000, 0 },
			{ 126840, 37000, 126840, 39000, 927 },
			{ 126840, 39000, 126840, 46000, 0 },
			{ 126840, 46000, 126840, 48000, 926 },
			{ 126840, 48000, 126840, 49000, 0 },
			{ 126840, 49000, 126840, 51000, 925 },
			{ 126840, 51000, 126840, 58000, 0 },
			{ 126840, 58000, 126840, 60000, 924 },
			{ 126840, 60000, 126840, 64000, 0 },
			{ 126840, 64000, 126840, 66000, 923 },
			{ 126840, 66000, 126840, 67000, 0 },
			{ 126840, 67000, 126840, 69000, 922 },
			{ 126840, 69000, 126840, 76000, 0 },
			{ 126840, 76000, 126840, 78000, 921 },
			{ 126840, 78000, 126840, 79000, 0 } };

	private int[][] road_975 = { { 131000, 90000, 126840, 90000, 974 },
			{ 126840, 90000, 126840, 88000, 919 },
			{ 126840, 88000, 126840, 81000, 0 },
			{ 126840, 81000, 126840, 79000, 920 },
			{ 126840, 79000, 131000, 80000, 976 },
			{ 131000, 80000, 131000, 90000, 0 } };

	private int[][] road_974 = { { 131000, 90000, 126840, 90000, 975 },
			{ 126840, 90000, 126840, 92000, 0 },
			{ 126840, 92000, 126840, 94000, 918 },
			{ 126840, 94000, 126840, 98690, 0 },
			{ 126840, 98690, 133160, 101310, 262 },
			{ 133160, 101310, 133160, 90000, 0 },
			{ 133160, 90000, 131000, 90000, 254 } };

	int[] road = { 974, 918, 975, 919, 920, 976, 921, 922, 923, 924, 925, 926,
			927, 928, 929, 274 };

	int[] blockade = { 2078976077, 2078976078, 2078976033, 2078976034,
			2078976075, 2078976076, 2078976035, 2078976028, 2078976029,
			2078976063, 2078976064, 2078976065, 2078976066, 2078976067,
			2078976068, 2078976069, 2078976030, 2078976032, 2078976024,
			2078976025, 2078976026, 2078976027, 2078976021, 2078976022,
			2078976019, 2078976020, 2078976007, 2078976005, 2078976006,
			2078975973 };

	@Override
	public Map<Integer, CSUBlockade> blockadeList() {
		Map<Integer, CSUBlockade> list = new TreeMap<>();

		list.put(2078976077, createBlockade(2078976077, blockade_2078976077));
		list.put(2078976078, createBlockade(2078976078, blockade_2078976078));
		list.put(2078976033, createBlockade(2078976033, blockade_2078976033));
		list.put(2078976034, createBlockade(2078976034, blockade_2078976034));
		list.put(2078976075, createBlockade(2078976075, blockade_2078976075));
		list.put(2078976076, createBlockade(2078976076, blockade_2078976076));
		list.put(2078976035, createBlockade(2078976035, blockade_2078976035));
		list.put(2078976028, createBlockade(2078976028, blockade_2078976028));
		list.put(2078976029, createBlockade(2078976029, blockade_2078976029));
		list.put(2078975973, createBlockade(2078975973, blockade_2078975973));
		list.put(2078976063, createBlockade(2078976063, blockade_2078976063));
		list.put(2078976064, createBlockade(2078976064, blockade_2078976064));
		list.put(2078976065, createBlockade(2078976065, blockade_2078976065));
		list.put(2078976066, createBlockade(2078976066, blockade_2078976066));
		list.put(2078976067, createBlockade(2078976067, blockade_2078976067));
		list.put(2078976068, createBlockade(2078976068, blockade_2078976068));
		list.put(2078976069, createBlockade(2078976069, blockade_2078976069));
		list.put(2078976030, createBlockade(2078976030, blockade_2078976030));
		list.put(2078976032, createBlockade(2078976032, blockade_2078976032));
		list.put(2078976006, createBlockade(2078976006, blockade_2078976006));
		list.put(2078976024, createBlockade(2078976024, blockade_2078976024));
		list.put(2078976025, createBlockade(2078976025, blockade_2078976025));
		list.put(2078976026, createBlockade(2078976026, blockade_2078976026));
		list.put(2078976027, createBlockade(2078976027, blockade_2078976027));
		list.put(2078976021, createBlockade(2078976021, blockade_2078976021));
		list.put(2078976022, createBlockade(2078976022, blockade_2078976022));
		list.put(2078976019, createBlockade(2078976019, blockade_2078976019));
		list.put(2078976020, createBlockade(2078976020, blockade_2078976020));
		list.put(2078976007, createBlockade(2078976007, blockade_2078976007));
		list.put(2078976005, createBlockade(2078976005, blockade_2078976005));

		return list;
	}

	@Override
	public List<CSURoad> roadList() {
		List<CSURoad> list = new ArrayList<>();

		list.add(createRoadEdge(974, road_974));
		list.add(createRoadEdge(918, road_918));
		list.add(createRoadEdge(975, road_975));
		list.add(createRoadEdge(919, road_919));
		list.add(createRoadEdge(920, road_920));
		list.add(createRoadEdge(976, road_976));
		list.add(createRoadEdge(921, road_921));
		list.add(createRoadEdge(922, road_922));
		list.add(createRoadEdge(923, road_923));
		list.add(createRoadEdge(924, road_924));
		list.add(createRoadEdge(925, road_925));
		list.add(createRoadEdge(926, road_926));
		list.add(createRoadEdge(927, road_927));
		list.add(createRoadEdge(928, road_928));
		list.add(createRoadEdge(929, road_929));
		list.add(createRoadEdge(274, road_274));

		return list;
	}

	@Override
	public int[] getBlockadeList(int roadId) {
		switch (roadId) {
		case 974:
			int[] a = { 2078976077, 2078976078 };
			return a;
		case 918:
			int[] b = { 2078976033, 2078976034 };
			return b;
		case 975:
			int[] c = { 2078976075, 2078976076 };
			return c;
		case 919:
			int[] d = { 2078976035 };
			return d;
		case 920:
			int[] e = { 2078976028, 2078976029 };
			return e;
		case 976:
			int[] f = { 2078976063, 2078976064, 2078976065, 2078976066,
					2078976067, 2078976068, 2078976069 };
			return f;
		case 921:
			int[] g = { 2078976030, 2078976032 };
			return g;
		case 922:
			int[] h = { 2078976024, 2078976025 };
			return h;
		case 923:
			int[] i = { 2078976026, 2078976027 };
			return i;
		case 924:
			int[] j = { 2078976021 };
			return j;
		case 925:
			int[] k = { 2078976022 };
			return k;
		case 926:
			int[] l = { 2078976019 };
			return l;
		case 927:
			int[] m = { 2078976020 };
			return m;
		case 928:
			int[] n = { 2078976007 };
			return n;
		case 929:
			int[] o = { 2078976005, 2078976006 };
			return o;
		case 274:
			int[] p = { 2078975973 };
			return p;
		default:
			return null;
		}
	}

	private CSUBlockade createBlockade(int id, int[] apexes) {
		EntityID blockadeId = new EntityID(id);

		int count = apexes.length;
		int[] vertexs = new int[count - 2];
		for (int i = 0; i < vertexs.length; i++) {
			vertexs[i] = apexes[i];
		}

		int center_x = apexes[count - 2], center_y = apexes[count - 1];

		return new CSUBlockade(blockadeId, vertexs, center_x, center_y);
	}

	private CSURoad createRoadEdge(int id, int[][] road) {
		List<CSUEdge> edges = new ArrayList<>();
		rescuecore2.misc.geometry.Point2D start = null, end = null;

		for (int i = 0; i < road.length; i++) {
			start = new rescuecore2.misc.geometry.Point2D(road[i][0],
					road[i][1]);
			end = new rescuecore2.misc.geometry.Point2D(road[i][2], road[i][3]);

			edges.add(new CSUEdge(start, end, road[i][4] != 0));
		}

		CSURoad csuRoad = new CSURoad(new EntityID(id), edges);

		return csuRoad;
	}

	public static void main(String[] args) {

		EscapeData_1 es = new EscapeData_1();
		es.print_road();
		es.print_blockade();

	}

	public void print_road() {
		String road = "public List<CSURoad> roadList() {\n\t"
				+ "List<CSURoad> list = new ArrayList<>();\n\n\t";
		for (int i = 0; i < this.road.length; i++) {
			road = road + "list.add(createRoadEdge(" + this.road[i] + ", road_"
					+ this.road[i] + "));\n\t";
		}
		road = road + "\n\treturn list;\n}";
		System.out.println(road);
	}

	public void print_blockade() {
		String blockade = "public Map<Integer, CSUBlockade> blockadeList() {\n\t"
				+ "Map<Integer, CSUBlockade> list = new TreeMap<>();\n\n\t";
		for (int i = 0; i < this.blockade.length; i++) {
			blockade = blockade + "list.put(" + this.blockade[i]
					+ ", createBlockade(" + this.blockade[i] + ", blockade_"
					+ this.blockade[i] + "));\n\t";
		}
		blockade = blockade + "\n\treturn list;\n}";
		System.out.println(blockade);
	}
}
